package mybatisdemo.test

import com.tsp.ssm.po.User
import mybatisdemo.dao.Userdao
import mybatisdemo.dao.UserdaoImpl
import mybatisdemo.mybatisfirst
import org.apache.ibatis.io.Resources
import org.apache.ibatis.session.SqlSessionFactory
import org.apache.ibatis.session.SqlSessionFactoryBuilder

/**
 * Created by 隼 on 2016/11/28.
 */
class UserdaoTest extends GroovyTestCase {
    private SqlSessionFactory sqlSessionFactory;
    // 此方法是在执行testFindUserById之前执行
    void setUp() {
        super.setUp()
        // 创建sqlSessionFactory
        //mybatis 配置文件
        String resource = "config/mybatis/sqlMaptest.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);

        //创建会话工厂,传入mybatis 配置文件
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);




    }

    void testFindUserById() {
        Userdao userdao=new UserdaoImpl(sqlSessionFactory);

        User user= userdao.findUserById(1);
        System.out.println(new mybatisfirst().UsertoString(user) );




    }

    void testFindUserByName() {

    }

    void testInsertUser() {

    }

    void testDeleteUser() {

    }
}
